<?php
require_once($application_folder."/controllers/navigator.php");
class Testovi extends navigator 
{

    function __construct()
    {
        parent::__construct(); 
        
        /************************************************************
        * CHECK LOGIN
        *************************************************************/
        if(!$this->session->userdata('logged_in')){
            redirect(base_url());
        }
        
    }
    
    function newuserform(){
        
        $this->layout->setLayout('layout_login');
        $data['typeofuser'] = $this->db->get('typeofuser')->result_array();
        $this->core_cms('login', $data, 'newuserform');
        
    }
    
   function loginform(){
        
        $this->layout->setLayout('layout_login');
        $this->core_cms('login', '', 'login');
        
    } 

    function loginuser(){
        
        if($this->validloginform()) {
           
            if($this->simple_login_secure->login($_POST['email'], $_POST['password'])){
                
                echo json_encode(array('action' => true)); 

            }else{

                echo json_encode(array('action' => false, 'msg' => '<p>Molimo unesite ispravne pristupne podatke!</p>')); 
            }
            
        }
        else{
            
            echo json_encode(array('action' => false, 'msg' => validation_errors()));
            
        }

    }    
    
    function validloginform() {

        $this->form_validation->set_rules('email','<strong>email</strong>','trim|xss_clean|required|valid_email');        
        $this->form_validation->set_rules('password','<strong>lozinku</strong>','trim|xss_clean|required');

        $this->form_validation->set_message('required','Molimo unesite %s!'); 
        $this->form_validation->set_message('valid_email','Polje %s mora biti validan mejl!'); 

        return $this->form_validation->run();

    }  

}